//
//  KDLoginButton.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/10/28.
//  Copyright © 2015年 魏强. All rights reserved.
//

#import "KDLoginButton.h"
#import "GBCircleView.h"
@interface KDLoginButton ()
@property (nonatomic, strong) GBCircleView *circleView;

@end
@implementation KDLoginButton


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = KDHeadColor;
        self.layer.cornerRadius = 3;
        self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self setTitle:@"登录" forState:UIControlStateNormal];
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return self;
}

#pragma mark - 登陆按钮开始变化，旋转
-(void)startCircle
{
//按钮变为圆形，往中间缩的动画
[UIView animateWithDuration:0.3 animations:^{
    self.x = screenW / 2.0 - 15;
    self.size = CGSizeMake(30, 30);
//self.frame = CGRectMake(screenW / 2.0 - 20, 300, 40, 40);
    self.layer.cornerRadius = 15;
    [self setTitle:@"" forState:UIControlStateNormal];
} completion:^(BOOL finished) {
    //生成旋转动画
    [self createCircle];
}];
}

#pragma mark - 生成旋转动画
-(void)createCircle
{
    GBCircleView *circleView = [[GBCircleView alloc] initWithFrame:CGRectMake(screenW / 2.0 - 11, self.y +4, 22, 22)];
    self.circleView = circleView;
    circleView.tintColor = [UIColor whiteColor];
    [circleView startAnimating];
    [self.superview addSubview:circleView];
}
#pragma mark - 请求失败，将所有控件移除
-(void)stopCircle
{
    [UIView animateWithDuration:0.3 animations:^{
        
        self.frame = CGRectMake(15,  self.y, screenW - 30, 30);
        self.layer.cornerRadius = 3.0;
       
    } completion:^(BOOL finished) {
        [self setTitle:@"登陆" forState:UIControlStateNormal];
        [_circleView stopAnimating];
        [_circleView removeFromSuperview];
    }];
    
}
@end
